   import 'package:flutter/material.dart';
   import 'package:date_format/date_format.dart';
  import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart';

class DatePickerPubPage extends StatefulWidget {
  DatePickerPubPage({Key key}) : super(key: key);

  @override
  _DatePickerPubPageState createState() => _DatePickerPubPageState();
}

class _DatePickerPubPageState extends State<DatePickerPubPage> {

  // var now = DateTime.now();

  DateTime _nowDate = DateTime.now();
  // var _nowTime = TimeOfDay(hour: 12, minute: 20);

  _showDatePicker(){
    DatePicker.showDatePicker(
      context,
      onMonthChangeStartWithFirstDate: true,
      pickerTheme: DateTimePickerTheme(
        showTitle: true,
        confirm: Text('确定', style: TextStyle(color: Colors.red)),
        cancel: Text('取消', style: TextStyle(color: Colors.cyan)),
      ),
      minDateTime: DateTime.parse('2013-06-09'),
      maxDateTime: DateTime.parse('2021-09-09'),
      initialDateTime: _nowDate,
      // dateFormat: 'yyyy-MMMM-dd',
      dateFormat: 'yy年-M月-d日 EEE,H时:m分',
      pickerMode: DateTimePickerMode.datetime,
      locale: DateTimePickerLocale.zh_cn,
      // onClose: () => print("----- onClose -----"),
      onCancel: () => print('onCancel'),
      // onChange: (dateTime, List<int> index) {
      //   setState(() {
      //     _nowDate = dateTime;
      //   });
      // },
      onConfirm: (dateTime, List<int> index) {
        setState(() {
          _nowDate = dateTime;
        });
      },
    );
  }





  // @override
  //   void initState() {
  //     // TODO: implement initState
  //     super.initState();
  //   }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('日期选择-第三方组件'),
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              children: <Widget>[
                InkWell(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text("${formatDate(_nowDate, [yyyy, '年', mm , '月', dd, '日', HH, ':', nn])}"),
                      Icon(Icons.arrow_drop_down)
                    ],
                  ),
                  // onTap: (){
                  //   print(this._showDatePicker());
                  // },
                  onTap: _showDatePicker,
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}